package com.ruoyi.threeViolation.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.system.domain.SysDictItem;
import com.ruoyi.system.mapper.SysDictItemMapper;
import com.ruoyi.threeViolation.vo.ViolationTemplateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.threeViolation.mapper.ViolationTemplateMapper;
import com.ruoyi.threeViolation.domain.ViolationTemplate;
import com.ruoyi.threeViolation.service.IViolationTemplateService;

/**
 * 三违模板管理Service业务层处理
 *
 * @author lth
 * @date 2023-12-18
 */
@Service
public class ViolationTemplateServiceImpl implements IViolationTemplateService
{
    @Autowired
    private ViolationTemplateMapper violationTemplateMapper;

    @Autowired
    private SysDictItemMapper sysDictItemMapper;
    /**
     * 查询三违模板管理
     *
     * @param id 三违模板管理主键
     * @return 三违模板管理
     */
    @Override
    public ViolationTemplate selectViolationTemplateById(String id)
    {
        return violationTemplateMapper.selectViolationTemplateById(id);
    }

    /**
     * 查询三违模板管理列表
     *
     * @param violationTemplate 三违模板管理
     * @return 三违模板管理
     */
    @Override
    public List<ViolationTemplate> selectViolationTemplateList(ViolationTemplate violationTemplate)
    {
        return violationTemplateMapper.selectViolationTemplateList(violationTemplate);
    }

    /**
     * 新增三违模板管理
     *
     * @param violationTemplate 三违模板管理
     * @return 结果
     */
    @Override
    public int insertViolationTemplate(ViolationTemplate violationTemplate)
    {
        return violationTemplateMapper.insertViolationTemplate(violationTemplate);
    }

    /**
     * 修改三违模板管理
     *
     * @param violationTemplate 三违模板管理
     * @return 结果
     */
    @Override
    public int updateViolationTemplate(ViolationTemplate violationTemplate)
    {
        return violationTemplateMapper.updateViolationTemplate(violationTemplate);
    }

    /**
     * 批量删除三违模板管理
     *
     * @param ids 需要删除的三违模板管理主键
     * @return 结果
     */
    @Override
    public int deleteViolationTemplateByIds(String[] ids)
    {
        return violationTemplateMapper.deleteViolationTemplateByIds(ids);
    }

    /**
     * 删除三违模板管理信息
     *
     * @param id 三违模板管理主键
     * @return 结果
     */
    @Override
    public int deleteViolationTemplateById(String id)
    {
        return violationTemplateMapper.deleteViolationTemplateById(id);
    }

    /**     查询三违volation_category volation_level列表
    * @Author lth
    * @Description //TODO
    * @Date 16:32 2023/12/18
    * @Param
    * @return
     **/
    @Override
    public List<ViolationTemplate> getCategoryList(ViolationTemplate vo) {
        List<ViolationTemplate> violationTemplates = violationTemplateMapper.selectViolationTemplateList(vo);
        List<ViolationTemplate> violationTemplateList = violationTemplates.stream().map(violationTemplate -> {
            String category = violationTemplate.getVolationCategory();
            String level = violationTemplate.getVolationLevel();

            SysDictItem categorySysDictItem = sysDictItemMapper.getCategoryList(category);
            SysDictItem levelSysDictItem = sysDictItemMapper.getLevelList(level);
            violationTemplate.setVolationCategory(categorySysDictItem.getItemText());
            violationTemplate.setVolationLevel(levelSysDictItem.getItemText());
            return violationTemplate;
        }).collect(Collectors.toList());

        return violationTemplateList;
    }
}
